package net.hualisheng.netty.controller;

import net.hualisheng.netty.entity.ResultModel;
import net.hualisheng.netty.service.CommonMQService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/red-pack")
public class GrabRedPackController {
    private static final Logger logger= LoggerFactory.getLogger(GrabRedPackController.class);
    @Autowired
    private CommonMQService service;

    @RequestMapping("/grab")
    @ResponseBody
    public ResultModel<String> grab(String userId){
        try {
            service.sendGradRedPack(userId);
            return  new ResultModel<>(0,userId,"你已成功抢到一个红包");
        } catch (Exception e) {
            logger.error("用户:"+userId+"抢红包操作失败");
            return new ResultModel<>(0,userId,"未抢到红包");
        } finally {
        }
    }
}
